#include "Layers/Model/MeterModel.h"
#include "TelltaleCtrl/Model/TelltaleModel.h"
#include "HmiAdapterRuntime.h"
#include "SDL/SDL.h"

uint64_t runtimeCount = 0;

void SystemCountRunning()
{
	runtimeCount++;
}


uint64_t GetSystemCount()
{
	return runtimeCount;
}

void InitView(ItuElementUnited* elementUnited)
{
	for(int i = 0; i < elementUnited->size_; i++)
	{
		elementUnited->views_[i].init(&elementUnited->views_[i]);
	}
}

void RefreshView(ItuElementUnited* elementUnited)
{
	for(int i = 0; i < elementUnited->size_; i++)
	{
		if(elementUnited->views_[i].isVaild_ && (0 == runtimeCount % elementUnited->views_[i].period_))
		{
			elementUnited->views_[i].refresh(&elementUnited->views_[i], false);
		}
		else
		{
			// widget not find, ignore
		}
	}
}

extern void ReportViewVisible(ItuElementUnited* elementUnited)
{
	for(int i = 0; i < elementUnited->size_; i++)
	{
		elementUnited->views_[i].reporting_self_validity(&elementUnited->views_[i]);
	}
}

void MeterModelInit()
{
	for(int i = 0; i < g_MeterModel.size_; i++)
	{
		g_MeterModel.models_[i]->init();
	}
}

void MeterModelRun()
{
	for(int i = 0; i < g_MeterModel.size_; i++)
	{
		if(0 == runtimeCount % g_MeterModel.models_[i]->period_)
		{
			g_MeterModel.models_[i]->run();
		}
	}
}

void MeterModelRelease()
{
	for(int i = 0; i < g_MeterModel.size_; i++)
	{
		g_MeterModel.models_[i]->release();
	}
}

void TelltaleModelInit()
{
	for(int i = 0; i < MAX_TELLTALE_MODEL_SIZE; i++)
	{
		g_TelltaleModel[i]->init();
	}
}

void TelltaleModelRun()
{
	for(int i = 0; i < MAX_TELLTALE_MODEL_SIZE; i++)
	{
		if(0 == runtimeCount % g_TelltaleModel[i]->period_)
		{
			g_TelltaleModel[i]->run();
		}
	}
}

void TelltaleModelRelease()
{
	for(int i = 0; i < MAX_TELLTALE_MODEL_SIZE; i++)
	{
		g_TelltaleModel[i]->release();
	}
}


